package com.java.basis.thread.n8.pool;

import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hslf.record.AnimationInfoAtom;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 固定线程池
 * 特点：
 * 		核心线程数==最大线程数（没有救济线程）
 * 		阻塞队列是无界的，可以放任意数量
 * 		适用于任务量已知，相对耗时的任务
 * @author wangning
 * @create 2022-02-09 16:32
 */
@Slf4j(topic = "c.TestThreadPoolExecutors01")
public class TestThreadPoolExecutors01 {
	public static void main(String[] args) {
		ExecutorService pool = Executors.newFixedThreadPool(2, new ThreadFactory() {
			private AtomicInteger t = new AtomicInteger();
			@Override
			public Thread newThread(Runnable r) {
				return new Thread(r, "mypool_t" + t.getAndIncrement());
			}

		});

		pool.execute(new Runnable() {
			@Override
			public void run() {
				log.debug("1");
			}
		});
		pool.execute(() -> {
			log.debug("2");
		});
		pool.execute(() -> {
			log.debug("3");
		});



	}
}
